﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Songhay.BiggestBox.Portable.Modules.ModelContext.Tests
{
    using Extensions;

    /// <summary>
    /// Tests for <see cref="IRestModelContextService"/>.
    /// </summary>
    public partial class IRestModelContextServiceTests
    {
        /// <summary>
        /// IRestModelContextService tests: should load remote earth tools XML asynchronous.
        /// </summary>
        /// <returns></returns>
        [TestCategory("Integration")]
        [TestMethod]
        [TestProperty("dumpPath", @"E:\~shares\dataRoot\Visual Studio 2012\Projects\Songhay.BiggestBox.Portable.Modules.ModelContext.Tests\RequestDumps\EarthToolsSunriseSunsetData.xml")]
        [TestProperty("href", "http://www.earthtools.org/sun/34.0561/118.4136/{0}/{1}/99/1")]
        public async Task ShouldLoadRemoteEarthToolsXmlAsync()
        {
            var dumpPath = this.TestContext.Properties["dumpPath"].ToString();
            var href = string.Format(this.TestContext.Properties["href"].ToString(), DateTime.Now.Day, DateTime.Now.Month);

            var xDoc = await this.TestContext.ShouldLoadRemoteXml(href);
            Assert.IsTrue(EarthToolsContext.InspectRemoteDocument(xDoc), "The expected Earth Tools XML document is not here)");

            this.TestContext.ShouldWriteXml(xDoc, dumpPath);
        }

        /// <summary>
        /// Noaa weather test: should read remote XML.
        /// </summary>
        [TestCategory("Integration")]
        [TestMethod]
        [TestProperty("dumpPath", @"E:\~shares\dataRoot\Visual Studio 2012\Projects\Songhay.BiggestBox.Portable.Modules.ModelContext.Tests\RequestDumps\NoaaWeather.xml")]
        [TestProperty("href", "http://www.weather.gov/xml/current_obs/KLAX.xml")]
        public async Task ShouldLoadRemoteNoaaXmlAsync()
        {
            var dumpPath = this.TestContext.Properties["dumpPath"].ToString();
            var href = this.TestContext.Properties["href"].ToString();

            var xDoc = await this.TestContext.ShouldLoadRemoteXml(href);
            Assert.IsTrue(NoaaWeatherContext.InspectRemoteDocument(xDoc), "The expected NOAA XML document is not here)");

            this.TestContext.ShouldWriteXml(xDoc, dumpPath);
        }
    }
}
